**************************************************************
** title:	The Motivation to Vote			 				**
** data:	ANES - publicly available					    **
** authors:	Blais and Daoust								**
** date:	March 2020								    	**
**************************************************************

*Clean and merge ANES 1972, 76, 80

**************************************************************
** 				Preparation	1972						   	**
**************************************************************

use "/Users/jfd/Downloads/anes1972dta/NES1972.dta", clear

*Age
gen age=V720294
drop if age==0

*Sex
gen female=0
replace female=1 if V720424==2

*Turnout
gen turnout_1972=0
replace turnout_1972=1 if V720477==1
replace turnout_1972=. if V720477==0

*Interest
gen interest=0
replace interest=0.5 if V720163==3 
replace interest=1 if V720163==1

*Education
gen edu=0
replace edu=1 if V720300 > 51

*Duty
gen duty=0
replace duty=1 if V720289==5

*PID
gen PID=. 
replace PID=0 if V720140==3 |  V720140==7 | V720140==8 | V720140==9
replace PID=0.33 if V720140==2 | V720140==4
replace PID=0.67 if V720140==1 | V720140==5
replace PID=1 if V720140==0 | V720140==6

*Care
gen care=0
replace care=1 if V720029==1

*Habit
gen habit_vote=0 
replace habit_vote=1 if V720156==1

gen habit_vote_lived=0 
replace habit_vote_lived=1 if V720156==1
replace habit_vote_lived=0 if V720419 < 10

gen habit_vote_abstain=0
replace habit_vote_abstain=1 if V720156==1 | V720156==5

gen habit_vote_abstain_lived=0
replace habit_vote_abstain_lived=1 if V720156==1 | V720156==5 
replace habit_vote_abstain_lived=0 if V720419 < 10

*Dummy to identify the election
gen election_1972=1

*Clean 
keep election_1972 turnout_1972 age female edu habit_vote interest habit_vote_abstain care PID duty habit_vote_lived habit_vote_abstain_lived

*Save
save "/Users/jfd/Desktop/NES1972_tomerge.dta", replace



**************************************************************
** 				Preparation	1976						   	**
**************************************************************

use "/Users/jfd/Downloads/anes1976dta/NES1976.dta", clear

*Age
gen age=V763369
drop if age==0

*Sex
gen female=0
replace female=1  if V763512==2

*Turnout
gen turnout_1976=0
replace turnout_1976=1 if V763655==1
replace turnout_1976=. if V763655==0

*Duty
gen duty=0
replace duty=1 if V763350==5

*Education
gen edu=0
replace edu=1 if V763384 > 12

*Interest
gen interest=0
replace interest=0.5 if V763031==3 
replace interest=1 if V763031==1

*Care
gen care=0
replace care=1 if V763030==1

*PID
gen PID=. 
replace PID=0 if V763174==3 |  V763174==7 | V763174==8 | V763174==9
replace PID=0.33 if V763174==2 | V763174==4
replace PID=0.67 if V763174==1 | V763174==5
replace PID=1 if V763174==0 | V763174==6

*Habit
gen habit_vote=0
replace habit_vote=1 if V763179==1

gen habit_vote_abstain=0
replace habit_vote_abstain=1 if V763179==1 |  V763179==5

gen habit_vote_lived=0
replace habit_vote_lived=1 if V763179==1
replace habit_vote_lived=0 if V763503 < 10

gen habit_vote_abstain_lived=0
replace habit_vote_abstain_lived=1 if V763179==1 |  V763179==5
replace habit_vote_abstain_lived=0 if V763503 < 10

*Dummy to identify the election 
gen election_1976=1

*Clean
keep election_1976 turnout_1976 age female edu habit_vote interest habit_vote_abstain care PID duty  habit_vote_lived habit_vote_abstain_lived

*Save
save "/Users/jfd/Desktop/NES1976_tomerge.dta", replace

**************************************************************
** 				Preparation	1980						   	**
**************************************************************

use "/Users/jfd/Downloads/anes1980dta/NES1980.dta", clear
 
*Age
gen age=V800408
drop if age==0

*Sex
gen female=0
replace female=1  if V800720==2

*Turnout validated
gen turnout_1980=0
replace turnout_1980=1 if  V801207==1

*Self reported turnout
gen turnout_1980_self=0
replace turnout_1980_self=1 if   V800988==1
drop if V800988==9

*Education
gen edu=0
replace edu=1 if V800429 > 12

*Duty
gen duty=0
replace duty=1 if V800145==5

*Interest
gen interest=0
replace interest=0.5 if V800053==3 
replace interest=1 if V800053==1

*Care
gen care=0
replace care=1 if V800061==1

*PID
gen PID=. 
replace PID=0 if V800775==3 |  V800775==7 | V800775==8 | V800775==9
replace PID=0.33 if V800775==2 | V800775==4
replace PID=0.67 if V800775==1 | V800775==5
replace PID=1 if V800775==0 | V800775==6

*Habit
gen habit_vote=0
replace habit_vote=1 if V800350==1

gen habit_vote_abstain=0
replace habit_vote_abstain=1 if V800350==1 |  V800350==5

gen habit_vote_lived=0
replace habit_vote_lived=1 if V800350==1
replace habit_vote_lived=0 if V800714 < 10

gen habit_vote_abstain_lived=0
replace habit_vote_abstain_lived=1 if V800350==1 |  V800350==5
replace habit_vote_abstain_lived=0 if V800714 < 10

*Dummy to identify election
gen election_1980=1

*Clean 
keep election_1980 turnout_1980 turnout_1980_self age female edu habit_vote interest habit_vote_abstain care PID duty habit_vote_lived habit_vote_abstain_lived





**************************************************************
** 							Append						   	**
**************************************************************
***Append cleaned 1972 and 1976 to the cleaned 1980
append using "/Users/jfd/Desktop/NES1972_tomerge.dta" "/Users/jfd/Desktop/NES1976_tomerge.dta"

*Save it
save "/Users/jfd/Desktop/merged_dataset_NES72-76-80.dta", replace


**************************************************************
** 						Analyses						   	**
**************************************************************

use "/Users/jfd/Desktop/merged_dataset_NES72-76-80.dta", clear

*Rescale age
drop if age < 18 //keep only eligible voters
replace age=age-18
replace age=age/80 if election_1972==1
replace age=age/81 if election_1976==1
replace age=age/75 if election_1980==1

*turnout
gen turnout=0
replace turnout=1 if turnout_1980==1 | turnout_1976==1 | turnout_1972==1

*Descriptive statistics
sum age female edu interest care PID duty habit_vote habit_vote_abstain turnout

*Label variable
label variable age Age
label variable female Woman 
label variable edu Education
label variable interest "Political Interest"
label variable habit_vote Consistency
label variable care Care
label variable duty "Civic Duty"

*Table 7.3. 
logit turnout_1972 age female edu interest habit_vote PID care duty i.habit_vote#c.interest i.habit_vote#c.PID i.habit_vote#i.care i.habit_vote#i.duty, robust
est store a1
logit turnout_1972 age female edu interest habit_vote_abstain PID care duty i.habit_vote_abstain#c.interest i.habit_vote_abstain#c.PID i.habit_vote_abstain#i.care i.habit_vote_abstain#i.duty, robust
est store a2

logit turnout_1976 age female edu interest habit_vote PID care duty i.habit_vote#c.interest i.habit_vote#c.PID i.habit_vote#i.care i.habit_vote#i.duty, robust
est store a3
logit turnout_1976 age female edu interest habit_vote_abstain PID care duty  i.habit_vote_abstain#c.interest i.habit_vote_abstain#c.PID i.habit_vote_abstain#i.care i.habit_vote_abstain#i.duty, robust
est store a4

logit turnout_1980 age female edu interest habit_vote PID care duty i.habit_vote#c.interest i.habit_vote#c.PID i.habit_vote#i.care i.habit_vote#i.duty, robust
est store a5
logit turnout_1980 age female edu interest habit_vote_abstain PID care duty  i.habit_vote_abstain#c.interest i.habit_vote_abstain#c.PID i.habit_vote_abstain#i.care i.habit_vote_abstain#i.duty, robust
est store a6

esttab  a1 a2 a3 a4 a5 a6  using "ANES_habit1.rtf",  ///
       label  pr2 b(2) se(2) replace /// 
					nonote addnotes("Entries are logistic regression coefficients." "Robust standard errors are in parentheses." ///
					 "* p < 0.05, ** p < 0.01, *** p < 0.001") 					 
	
	
*Table 7.4
logit turnout_1972 age female edu interest habit_vote_lived PID care duty i.habit_vote_lived#c.interest i.habit_vote_lived#c.PID i.habit_vote_lived#i.care i.habit_vote_lived#i.duty, robust
est store a1
logit turnout_1972 age female edu interest habit_vote_abstain_lived PID care duty i.habit_vote_abstain_lived#c.interest i.habit_vote_abstain_lived#c.PID i.habit_vote_abstain_lived#i.care i.habit_vote_abstain_lived#i.duty, robust
est store a2

logit turnout_1976 age female edu interest habit_vote_lived PID care duty i.habit_vote_lived#c.interest i.habit_vote_lived#c.PID i.habit_vote_lived#i.care i.habit_vote_lived#i.duty, robust
est store a3
logit turnout_1976 age female edu interest habit_vote_abstain_lived PID care duty  i.habit_vote_abstain_lived#c.interest i.habit_vote_abstain_lived#c.PID i.habit_vote_abstain_lived#i.care i.habit_vote_abstain_lived#i.duty, robust
est store a4

logit turnout_1980 age female edu interest habit_vote_lived PID care duty i.habit_vote_lived#c.interest i.habit_vote_lived#c.PID i.habit_vote_lived#i.care i.habit_vote_lived#i.duty, robust
est store a5
logit turnout_1980 age female edu interest habit_vote_abstain_lived PID care duty  i.habit_vote_abstain_lived#c.interest i.habit_vote_abstain_lived#c.PID i.habit_vote_abstain_lived#i.care i.habit_vote_abstain_lived#i.duty, robust
est store a6

esttab  a1 a2 a3 a4 a5 a6  using "ANES_10years_condition.rtf",       label  pr2 b(2) se(2) replace /// 
					nonote addnotes("Entries are logistic regression coefficients." "Robust standard errors are in parentheses." ///
					 "* p < 0.05, ** p < 0.01, *** p < 0.001") 	

*Appendix 
*Table A5
logit turnout_1980 age female edu interest PID care duty habit_vote i.habit_vote#c.interest i.habit_vote#c.PID i.habit_vote##i.care  i.habit_vote##i.duty, robust
est store M1
logit turnout_1980 age female edu interest PID care duty habit_vote_abstain i.habit_vote_abstain#c.interest i.habit_vote_abstain#c.PID i.habit_vote_abstain#i.care  i.habit_vote_abstain#i.duty, robust
est store M2

esttab  M1 M2  using "ANES_habit_1980_validated.rtf",       label  pr2 b(2) se(2) replace /// 
					nonote addnotes("Entries are logistic regression coefficients." "Robust standard errors are in parentheses." ///
					 "* p < 0.05, ** p < 0.01, *** p < 0.001") 	
	
